package com.cy.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

@WebFilter("/*")
public class HTMLFilter implements Filter {

    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest) servletRequest;
        // 获得请求路径  获取的是8080之后的地址
        String uri = request.getRequestURI();
        if(uri.endsWith(".html")){
            String pageName = uri.substring(1, uri.indexOf(".html"));
            request.setAttribute("pageName",pageName);
            request.getRequestDispatcher("/html").forward(request,servletResponse);
            return;
        }
        filterChain.doFilter(request,servletResponse);
    }
}
